/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */

//思路一
struct ListNode* mergeTwoLists(struct ListNode* list1, struct ListNode* list2){
    if(!list1)
        return list2;
    if(!list2)
        return list1;
    struct ListNode* newhead = NULL;
    struct ListNode* tailnode =NULL;
    if(list1->val <= list2->val){
        newhead = list1;
        list1 = list1->next;
    }
    else{
        newhead = list2;
        list2 = list2->next;
    }
    tailnode = newhead;
    while(list1 && list2){
        if(list1->val <= list2->val){
            tailnode->next = list1;
            list1 = list1->next;
        }
        else{
            tailnode->next = list2;
            list2 = list2->next;
        }
        tailnode = tailnode->next;
    }
    tailnode->next = !list1? list2: list1;
    return newhead;
}